﻿using UnityEngine;

namespace PnFramework.Unity
{
    public class Vector2Kit
    {
        /// <summary>
        /// 根据屏幕获取随机位置
        /// </summary>
        /// <returns>屏幕坐标</returns>
        public static Vector2 GetRomdomPos()
        {
            var pos = Camera.main.transform.position;
            var cornerPos = Camera.main.ViewportToWorldPoint(new Vector3(1f, 1f, Mathf.Abs(pos.z)));
            float px = Random.Range(pos.x - (cornerPos.x - pos.x), cornerPos.x);
            float py = Random.Range(pos.y - (cornerPos.y - pos.y), cornerPos.y);
            return new Vector2(px, py);
        }
    }
}